import 'package:city_pickers/city_pickers.dart';
import 'package:city_pickers/modal/result.dart';
import 'package:flutter/material.dart';

class SearchBarEnhance extends StatefulWidget {
  // const SearchBarEnhance({super.key});
  final bool? showLocation;
  final Function? goBackCallback;
  final String? inputValue;
  final String? intputHint;
  final Function? onCancel;
  final bool? showMap;
  final Function? onSearch;
  final ValueChanged<String>? onSearchSubmit;

  SearchBarEnhance(
      {this.showLocation,
      this.goBackCallback,
      this.inputValue,
      this.intputHint,
      this.onCancel,
      this.showMap,
      this.onSearch,
      this.onSearchSubmit});

  @override
  State<SearchBarEnhance> createState() => _SearchBarEnhanceState();
}

class _SearchBarEnhanceState extends State<SearchBarEnhance> {


  List<HotCity> hotCities =[];


  @override
  void initState() {
    super.initState();
    hotCities.add(HotCity(name: "上海", id: "310107"));
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: [
        if (widget.showLocation == null)
          GestureDetector(
            onTap: () async {
              Result? result = await CityPickers.showCitiesSelector(
                context: context,
                cityItemStyle:BaseStyle(color: Colors.black, fontSize: 16),
                useSearchAppBar: true,
                hotCities: hotCities
              );
            },
            child: const Padding(
              padding: EdgeInsets.only(right: 20),
              child: Column(
                children: [
                  Icon(
                    Icons.location_on_outlined,
                    size: 18,
                  ),
                  Text(
                    "上海",
                    style: TextStyle(fontSize: 12, color: Colors.black),
                  )
                ],
              ),
            ),
          ),
        if (widget.goBackCallback != null)
          Padding(
            padding: EdgeInsets.only(right: 20),
            child: GestureDetector(
              onTap: () => widget.goBackCallback,
              child: const Icon(
                Icons.chevron_left,
                color: Colors.black,
              ),
            ),
          ),
        Expanded(
          child: Container(
              height: 40,
              alignment: Alignment.center,
              decoration: BoxDecoration(
                  color: Colors.grey[200],
                  borderRadius: BorderRadius.circular(30.0)),
              child: const TextField(
                decoration: InputDecoration(
                    // contentPadding: EdgeInsets.all(0),
                    border: InputBorder.none,
                    prefixIcon: Icon(
                      Icons.search,
                      size: 18,
                      color: Colors.grey,
                    ),
                    hintText: '搜索'),
              )),
        ),
        if (widget.onCancel != null)
          GestureDetector(
            onTap: () => {},
            child: const Padding(
              padding: EdgeInsets.only(right: 20, left: 20),
              child: Text(
                "取消",
                style: TextStyle(fontSize: 18),
              ),
            ),
          ),
        if (widget.showMap != null)
          Image.asset(
            "images/my_position.png",
            width: 20,
          ),
      ],
    );
  }
}
